package com.phuc.app.vuivui.sqlite;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * Class common data access object.
 * @author Phuc
 *
 * @param <A>
 */
public abstract class CommonDao {

	public static Cursor executeSql(String sql, String... selectionArgs) {
		SQLiteDatabase db = DatabaseAdapter.open();
		Cursor cursor = db.rawQuery(sql, selectionArgs);
		cursor.moveToFirst();
		DatabaseAdapter.close();
		return cursor;
	}
	
	/**
	 * Method get all record in table
	 * @return null if have error
	 */
	public static Cursor getAll(String tableName) {
		SQLiteDatabase db = DatabaseAdapter.open();
		Cursor cursor = db.query(tableName, null, null, null, null, null, null);
		cursor.moveToFirst();
		DatabaseAdapter.close();
		return cursor;
	}
}
